﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KerriganDirection.DirectionServiceWCF;
using System.Diagnostics;
using KerriganDirection.Helpers;
using System.Windows.Controls;
using System.ComponentModel;

namespace KerriganDirection.InstructorMgt
{
    public class InstructorModule : INotifyPropertyChanged
    {
        #region NotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

        #endregion

        #region Properties

        private InstructorDC _InstructorVO;
        public InstructorDC InstructorVO 
        {
            get
            {
                return this._InstructorVO;
            }
            set
            {
                this._InstructorVO = value;
                OnPropertyChanged("InstructorVO");
            }
        }

        private MainModule _MainModuleVO;
        public MainModule MainModuleVO 
        {
            get
            {
                return this._MainModuleVO;
            }
            set
            {
                this._MainModuleVO = value;
                OnPropertyChanged("MainModuleVO");
            }
        }

        private ucAddInstructor _UcAddInstructorVO;
        public ucAddInstructor UcAddInstructorVO 
        {
            get
            {
                return this._UcAddInstructorVO;
            }
            set
            {
                this._UcAddInstructorVO = value;
                OnPropertyChanged("UcAddInstructorVO");
            }
        }

        public ucEditInstructor _UcEditInstructorVO;
        public ucEditInstructor UcEditInstructorVO 
        {
            get
            {
                return this._UcEditInstructorVO;
            }
            set
            {
                this._UcEditInstructorVO = value;
                OnPropertyChanged("UcEditInstructorVO");
            }
        }

        private ucInstructorsList _UcInstructorListVO;
        public ucInstructorsList UcInstructorListVO 
        {
            get
            {
                return this._UcInstructorListVO;
            }
            set
            {
                this._UcInstructorListVO = value;
                OnPropertyChanged("UcInstructorListVO");
            }
        }

        private ucInstructorOptions _UcInstructorOptionsVO;
        public ucInstructorOptions UcInstructorOptionsVO
        {
            get
            {
                return this._UcInstructorOptionsVO;
            }
            set
            {
                this._UcInstructorOptionsVO = value;
                OnPropertyChanged("UcInstructorOptionsVO");
            }
        }

        private ucAddInstructorAvailability _UcAddInstructorAvailabilityVO;
        public ucAddInstructorAvailability UcAddInstructorAvailabilityVO
        {
            get
            {
                return this._UcAddInstructorAvailabilityVO;
            }
            set
            {
                this._UcAddInstructorAvailabilityVO = value;
                OnPropertyChanged("UcAddInstructorAvailabilityVO");
            }
        }

        private vwGetInstructor[] _ListInstructorsVO;
        public vwGetInstructor[] ListInstructorsVO
        {
            get
            {
                return this._ListInstructorsVO;
            }
            set
            {
                this._ListInstructorsVO = value;
                OnPropertyChanged("ListInstructorsVO");
            }
        }

        private vwGetInstructorAvailability[] _ListInstructorsAvailabilityVO;
        public vwGetInstructorAvailability[] ListInstructorsAvailabilityVO
        {
            get
            {
                return this._ListInstructorsAvailabilityVO;
            }
            set
            {
                this._ListInstructorsAvailabilityVO = value;
                OnPropertyChanged("ListInstructorsAvailabilityVO");
            }
        }

        private InstructorAvailabilityDC _InstructorAvailabilityVO;
        public InstructorAvailabilityDC InstructorAvailabilityVO
        {
            get
            {
                return this._InstructorAvailabilityVO;
            }
            set
            {
                this._InstructorAvailabilityVO = value;
                OnPropertyChanged("InstructorAvailabilityVO");
            }
        }

        #endregion

        #region Contructors

        public InstructorModule()
        {
        }

        #endregion

        #region Methods

        public void InitModule()
        {
            try
            {
                this.MainModuleVO = (App.Current.Windows[0] as MainWindow).MainModuleVO;
                
                RefreshList();

                this.UcInstructorListVO = new ucInstructorsList();
                this.UcInstructorOptionsVO = new ucInstructorOptions();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void RefreshList()
        {
            //Initialization List
            this.GetListInstructor();
            this.GetListInstructorAvailability();
        }

        public void SetInstructor()
        {
            try
            {
                ServiceProxy.Service.SetInstructor(this.InstructorVO);
                this.InstructorVO = new InstructorDC();
                this.MainModuleVO.GoToLitInstructor();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void SetInstructorAvailability()
        {
            try
            {
                ServiceProxy.Service.AddAvaibilityForInstructor(this.InstructorAvailabilityVO);
                this.InstructorAvailabilityVO = new InstructorAvailabilityDC();
                this.MainModuleVO.GoToLitInstructor();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void DeleteInstructor(int id)
        {
            try
            {
                ServiceProxy.Service.DeleteInstructor(id);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void DeleteInstructorAvailability(int id)
        {
            try
            {
                ServiceProxy.Service.DeleteInstructorAvaibility(id);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void GetInstructor(int IdInstructor)
        {
            try
            {
                this.InstructorVO = null;
                this.InstructorVO = ServiceProxy.Service.GetInstructor(IdInstructor);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void GetListInstructor()
        {
            try
            {
                this.ListInstructorsVO = ServiceProxy.Service.GetListInstructorsToDisplay();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void GetListInstructorAvailability()
        {
            try
            {
                this.ListInstructorsAvailabilityVO = ServiceProxy.Service.GetListInstructorsAvailabilityToDisplay();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        #endregion
    }
}
